home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
User's Choice Windows CD
/
User's Choice Windows CD (CMS Software)(1993).iso
/
win_u_z
/
xlock_dv.zip
/
SOURCES.ZIP
/
QIX.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-08-28
|
4KB
|
208 lines
#ifndef lint
static char sccsid[] = "@(#)qix.c 22.3 89/09/20";
#endif
/*-
* qix.c - The old standby vector swirl for the xlock X11 terminal locker.
*
* Copyright (c) 1989 by Sun Microsystems Inc.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notice appear in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation.
*
* This file is provided AS IS with no warranties of any kind. The author
* shall have no liability with respect to the infringement of copyrights,
* trade secrets or any patents by this file or any part thereof. In no
* event will the author be liable for any lost revenue or profits or
* other special, indirect and consequential damages.
*
* Comments and additions should be sent to the author:
*
* naughton@sun.com
*
* Patrick J. Naughton
* Window Systems Group, MS 14-40
* Sun Microsystems, Inc.
* 2550 Garcia Ave
* Mountain View, CA 94043
*
* Revision History:
* 20-Sep-89: Lint.
* 24-Mar-89: Written.
*/
#include <X11/Xos.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
static Display *Dsp;
static Window Win;
static GC Gc,
eraseGC = (GC) 0;
static int timeout;
static int Nlines;
static int color;
static unsigned long pix = 0;
static long startTime;
static int first,
last,
dx1,
dy1,
dx2,
dy2,
x1,
y1,
x2,
y2,
offset,
delta,
width,
height;
typedef struct {
int x,
y;
} point;
static point *lineq = (point *) 0;
static long
seconds()
{
struct timeval foo;
gettimeofday(&foo, (struct timezone *) 0);
return (foo.tv_sec);
}
void
initqix(d, w, g, c, t, n)
Display *d;
Window w;
GC g;
int c,
t,
n;
{
XWindowAttributes xgwa;
XGCValues xgcv;
startTime = seconds();
if ((lineq) || (n != Nlines)) {
if (lineq)
free((char *) lineq);
lineq = (point *) malloc(n * sizeof(point));
Nlines = n;
}
Dsp = d;
Win = w;
Gc = g;
color = c;
timeout = t;
if (eraseGC == (GC) 0) {
xgcv.foreground = BlackPixel(Dsp, 0);
eraseGC = XCreateGC(Dsp, Win, GCForeground, &xgcv);
}
if (!color)
XSetForeground(Dsp, Gc, WhitePixel(Dsp, 0));
XGetWindowAttributes(Dsp, Win, &xgwa);
width = xgwa.width;
height = xgwa.height;
if (width < 100) /* icon window */
delta = 2;
else
delta = 15;
offset = delta / 3;
last = 0;
srandom(time((long *) 0));
dx1 = ((rand() >> 5) & (width - 1)) + 50;
dy1 = ((rand() >> 5) & (height - 1)) + 50;
dx2 = ((rand() >> 5) & (width - 1)) + 50;
dy2 = ((rand() >> 5) & (height - 1)) + 50;
x1 = (rand() >> 5) & width;
y1 = (rand() >> 5) & height;
x2 = (rand() >> 5) & width;
y2 = (rand() >> 5) & height;
XFillRectangle(Dsp, Win, eraseGC, 0, 0, width, height);
}
int
qixdone()
{
return (seconds() - startTime > timeout);
}
void
drawqix()
{
register int n = Nlines;
while (n--) {
first = (last + 2) % Nlines;
XDrawLine(Dsp, Win, eraseGC,
lineq[first].x, lineq[first].y,
lineq[first + 1].x, lineq[first + 1].y);
x1 += dx1;
y1 += dy1;
x2 += dx2;
y2 += dy2;
check_bounds_x(x1, &dx1);
check_bounds_y(y1, &dy1);
check_bounds_x(x2, &dx2);
check_bounds_y(y2, &dy2);
if (color) {
XSetForeground(Dsp, Gc, pix++);
pix %= 254;
}
XDrawLine(Dsp, Win, Gc, x1, y1, x2, y2);
en_queue(x1, y1, &last);
en_queue(x2, y2, &last);
}
}
static
en_queue(x, y, head)
int x,
y;
int *head;
{
lineq[*head].x = x;
lineq[*head].y = y;
*head = (*head + 1) % Nlines;
}
static
check_bounds_y(y, dy)
int y,
*dy;
{
if (y < 0) {
*dy = ((rand() >> 3) & delta) + offset;
}
if (y > height) {
*dy = -((rand() >> 3) & delta) - offset;
}
}
static
check_bounds_x(x, dx)
int x,
*dx;
{
if (x < 0) {
*dx = ((rand() >> 3) & delta) + offset;
}
if (x > width) {
*dx = -((rand() >> 3) & delta) - offset;
}
}